package org.itboys.mobile.controller.weixin.session;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.service.mongo.weixin.member.SundayWeixinMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2017年5月23日
 * 描述：圣代__微信端__session__controller。
 * **********此接口仅供测试开发使用，项目转为生产环境后，不要启用
 */
@Controller
@RequestMapping("/sunday/weixin/session")
public class SundayWeixinSessionController extends BaseController {
    @Autowired
    private SundayWeixinMemberService memberService;

    /**
     * 将用户信息保存至session中
     * @param request
     * @param response
     * @param memberId
     */
    @RequestMapping("/setSession")
    public void setSession(HttpServletRequest request,
                           HttpServletResponse response,
                           @RequestParam(value="memberId",required=true)Long memberId){
        memberService.insertMemberToSession(request, memberId, null);
        AjaxUtils.renderJsonporJson(response, null,
                ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
    }
    /**
     * 将用户信息保存至session中
     * @param request
     * @param response
     * @param memberId
     */
    @RequestMapping("/clearSession")
    public void clearSession(HttpServletRequest request,
                           HttpServletResponse response,
                           @RequestParam(value="memberId",required=true)Long memberId){
        memberService.clearMemberToSession(request, memberId);
        AjaxUtils.renderJsonporJson(response, null,
                ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.SUCCESS_CODE, CommonConstants.SUCCESS));
    }

}
